export default class MoleCtrl extends Laya.Script {

    constructor() { 
        super(); 
        this.isUp=false;
        this.isDowm=false;
        // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    }
    onAwake(){
        this.randomUp();
    }
    onUpdate(){
        if(this.isUp){
            this.owner.transform.translate(new Laya.Vector3(0,0.1,0));
            if(this.owner.transform.localPosition.y>=2.5){
                this.isUp=false;
                this.owner.transform.localPosition=new Laya.Vector3(0,2.5,0);

                Laya.stage.timerOnce(1000,this,function(){this.isDowm=true})
            }
        }
        if(this.isDowm){
            this.owner.transform.translate(new Laya.Vector3(0,-0.1,0));
            if(this.owner.transform.localPosition.y<=0){
                this.isDowm=false;
                this.owner.transform.localPosition=new Laya.Vector3();
                this.randomUp();
            }
        }
    }
    randomUp(){
        var value=Math.random();
        Laya.stage.timerOnce(value*6000,this,function(){this.isUp=true})
    }
    Knock(){
        this.owner.transform.localPosition=new Laya.Vector3();
        this.isUp=false;
        this.isDowm=false;
    }
}